    /**
 * 工具类
 */
define(function (require, exports, module) {
    var $ = require("jquery");
    var ui = require("@yunke/core/ui");
    var staticPublicUtil = require('@yunke/core/util').default;

    var Util = {
        //跳转登录页面，默认登陆后重定向回当前页面
        goToLoginPage: function (url) {
            url = (typeof(url) == 'undefined' || url == null) ? location.href : url;
            if (url == '') {
                location.href = "/login.shtml";
            }
            else {
                location.href = "/login.shtml?ret_url=" + encodeURIComponent(url);
            }
        },
        /**
         * 封装jQuery ajax方法
         * @param {Object} options
         * @returns {undefined}
         */
        myAjax: function (options) {
            var data = options["data"] || {};
            var async = typeof(options["async"]) == 'undefined' ? true : options["async"];

            var needToken = data['NEED_TOKEN'] !== false;
            delete data['NEED_TOKEN'];

            if (needToken) {
                var token = data["token"] || this.getToken();
                if (token) {
                    data["token"] = token;
                }
            }

            var self = this;
            return $.ajax({
                url: options["url"],
                type: options["type"],
                context: this,
                cache: false,
                async: async,
                data: data,
                success: function (json) {
                    if (typeof json === "string") {
                        try {
                            json = $.parseJSON(json);
                        } catch (e) {
                            window.console && console.log(e);
                            json = {};
                        }
                    }
                    var retCode = json.retCode;
                    if (retCode == "-1168002") {//未登录
                        self.goToLoginPage();
                    } else if (retCode === '-1168201' || retCode === '-1168202' || retCode === '-1168203') {//权限
                        Util.showNoPagePermission(json.errMsg);
                        //} else if (retCode.indexOf('-116') === 0) {//系统错误
                        //    self.alert(json['errMsg'] || "系统错误，请稍后再试");
                    } else if (retCode === '-1190151') {
                        Util.showNoFunctionPermission(json['errMsg']);
                    } else if (typeof options["success"] == "function") {
                        options["success"].call(options["context"], json);
                    }
                },
                error: function (xhr, txtStatus) {
                    if (options["error"]) {
                        options["error"].call(options["context"], xhr, txtStatus);
                    }
                    else {
                        self.alert("服务器系统内部错误，请稍后再试！");
                    }
                },
                complete: function (xhr, txtStatus) {
                    if (typeof options['complete'] == "function") {
                        options['complete'].call(options['context'], xhr, txtStatus);
                    }
                }
            });
        },
        /**
         * 展示无页面访问权限提示
         */
        showNoPagePermission: function (errMsg) {
            Util.showDialog({
                id: "__permission_alert__",
                title: '提示',
                fixed: true,
                content: errMsg || '对不起，您没有权限访问该页面',
                width: 350,
                okValue: '返回首页',
                cancelDisplay: false,
                ok: function () {
                    location.href = '/';
                    return true;
                },
                cancel: function () {
                    location.href = '/';
                    return true;
                }
            });
        },
        /**
         * 展示无功能访问权限提示
         */
        showNoFunctionPermission: function (message) {
            Util.showDialog({
                id: "__permission_alert__",
                title: '提示',
                fixed: true,
                content: message || '对不起，您没有权限访问该功能',
                width: 350,
                okValue: '确定',
                cancelDisplay: false,
                ok: function () {
                    //location.href = '/';
                    return true;
                },
                cancel: function () {
                    return true;
                }
            });
        },
        /**
         * 获取项目列表
         * @returns {undefined}
         */
        getProjList: function (callback, context) {
            var url = G_CONFIG["api_prefix"] + "/qmyx/customer-manage/get-project-list";
            this.myAjax({
                url: url,
                type: "get",
                context: this,
                success: function (json) {
                    if (json.retCode == 0) {
                        callback.call(context, json.data);
                    } else {
                        ui.showErrTip(json.errMsg || json.retMsg);
                    }
                }
            });
        },
        /**
         * 根据参数code获取参数值列表
         * @param {type} param_code 参数code
         * @param {type} scope_id token或proj_id
         * @param {type} callback 回调
         * @param {type} context 上下文对象
         * @returns {undefined}
         */
        getParamValuesByCode: function (param_code, scope_id, callback, context) {
            var url = G_CONFIG["api_prefix"] + "/qmyx/para-setting/get-param-values-by-code";
            var data = {
                scope_id: scope_id,
                param_code: param_code
            };
            this.myAjax({
                url: url,
                type: "get",
                context: this,
                data: data,
                success: function (json) {
                    if (json.retCode == 0) {
                        callback.call(context, json.data);
                    } else {
                        ui.showErrTip(json.errMsg);
                    }
                }
            });
        }
    };

    for (var key in staticPublicUtil) {
        if (staticPublicUtil.hasOwnProperty(key)) {
            Util[key] = staticPublicUtil[key];
        }
    }

    return Util;
});